// main 包 代表编译成可执行性文件
// go语言中 声明的变量必须使用， 不使用时会报错
package main

import (
	"fmt"
	"strings"
)

// 批量声明  全局变量
var (
	sex string
	age int
)

const (
	b1 = 20
	a1 = 10
	a2 = iota // 相当于索引 下标
	a3
	a4 = 100
	a5
)

// _ 通常标示匿名变量，通常用于忽略变量
func main() {

	fmt.Println(a1)
	fmt.Println(a2)
	fmt.Println(a3)
	fmt.Println(a4)
	fmt.Println(a5)

	fmt.Println("dadasdad")
	// String name ;
	// var 变量名 类型
	var name string
	// 简短变量声明 只能在函数中使用
	userName := "dadasd"

	//
	fmt.Println(userName)
	name = "this is a String"
	fmt.Println(name)
	fmt.Printf("this var name is: %s\n", name)
	fmt.Printf("sex is %s\n", sex)
	fmt.Printf("age %d\n", age)

	fmt.Printf("age typs= %T\n", age)

	fmt.Println(test1(10, 20))
	homeWork()
	fmt.Println()
	deferDemo()

	fn(void)
}

func test1(x int, y int) (ret int, ret2 int) {
	return x + y, y
}

func homeWork() {
	str := "how do I do"
	wordMap := make(map[string]int)
	fmt.Println(wordMap)
	split := strings.Split(str, " ")
	for _, v := range split {
		wordMap[v]++
	}

	for index, value := range wordMap {
		fmt.Printf("the key %s count is %d \n", index, value)
	}
}

func deferDemo() {
	fmt.Println("statrt")
	defer fmt.Println("defer")
	fmt.Println("end")
}

func void() int {
	fmt.Println("this is a blank func")
	return 10
}
func fn(x func() int) {
	ret := x()
	fmt.Println("result", ret)
}
